//
//  VehicleManageCell.m
//  阿帕
//
//  Created 阿帕 on 2019/12/26.
//  Copyright © 2019 GCY. All rights reserved.
//

#import "VehicleManageCell.h"

@interface VehicleManageCell ()
@property (weak, nonatomic) IBOutlet UILabel *vehicleNumLabel;
@property (weak, nonatomic) IBOutlet UILabel *bindTypeLabel;
@property (weak, nonatomic) IBOutlet UIView *buttonBgView;
@property (weak, nonatomic) IBOutlet UIView *hLine;

@property (weak, nonatomic) IBOutlet UIButton *authStatusBtn;
@property (weak, nonatomic) IBOutlet UILabel *certificateDueLabel;
@property (weak, nonatomic) IBOutlet UILabel *banResionLabel;

@end

@implementation VehicleManageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    _vehicleNumLabel.textColor = Dark_TextColor;
    _bindTypeLabel.textColor = Light_TextColor;
    _hLine.backgroundColor = BackgroundColor;
    
    
    _authStatusBtn.layer.cornerRadius = 7.0f;
    _authStatusBtn.clipsToBounds = YES;
    _certificateDueLabel.layer.cornerRadius = 4.0f;
    _certificateDueLabel.clipsToBounds = YES;
}

- (void)buttonClick:(UIButton *)button {
    if (self.delegate && [self.delegate respondsToSelector:@selector(cellButtonIndexClick:withButton:)]) {
        [self.delegate cellButtonIndexClick:button.tag withButton:button];
    }
}

- (void)setModel:(VehicleListModel *)model {
    
    _model = model;
    
    [StatusTextJudge authStatusJudge:model.authStatusExt authMsg:model.authMsg label:_banResionLabel button:_authStatusBtn];
    _certificateDueLabel.hidden = model.vehicleCertificateHasDue == 0 ? YES : NO;
    
    [_buttonBgView removeAllSubviews];
    NSMutableArray *btnTitles = @[@"冻结", @"编辑", @"删除"].mutableCopy;
    NSMutableArray *btnImages = @[@"gcy_icon_sjgl_dongjie", @"gcy_icon_yundan_edit", @"gcy_icon_yundan_delete"].mutableCopy;
    if (![DCSpeedy isBlankString:model.qrCode]) {
        [btnTitles insertObject:@"车辆码" atIndex:1];
        [btnImages insertObject:@"gcy_my_saoma" atIndex:1];
    }
    for (int i=0; i<btnTitles.count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.tag = 100 + i;
        [button setBackgroundColor:[UIColor whiteColor]];
        [button setTitle:btnTitles[i] forState:UIControlStateNormal];
        button.titleLabel.font = font(14);
        [button setTitleColor:Dark_TextColor forState:UIControlStateNormal];
        [button setImage:[image(btnImages[i]) imageByTintColor:UIColor.grayColor] forState:UIControlStateNormal];
        button.frame = CGRectMake(ScreenW/btnTitles.count*i, 0, ScreenW/btnTitles.count,45);
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [_buttonBgView addSubview:button];
        
        [button layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:5];
        
    }
    
    //操作按钮改变
    UIButton *dongjieBtn = [self viewWithTag:100];
    //    UIButton *jiedongBtn = [self viewWithTag:101];
    
    //是否冻结（0-未冻结 1-已冻结）
    if ([CJStringWithFormat(@"%ld",(long)model.isFreeze) isEqual:@"0"]) {
        //未冻结
        [dongjieBtn setTitle:@"冻结" forState:UIControlStateNormal];
    } else {
        [dongjieBtn setTitle:@"解冻" forState:UIControlStateNormal];
    }
    
    _vehicleNumLabel.text = CJStringWithFormat(@"车辆牌照号:%@", model.licenseNumber);
    if ([model.bindStatusName isEqual:@"未绑定司机"]) {
        _bindTypeLabel.text = model.bindStatusName;
    } else {
        _bindTypeLabel.text = [NSString stringWithFormat:@"%@：%@  手机号：%@", model.bindStatusName, model.driverName, model.driverPhone];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
}

@end
